namespace Bread.Utility;

public static class DateTimeHelper
{
    public static string GetWeekString(this DateTime time)
    {
        switch (time.DayOfWeek) {
            case DayOfWeek.Monday:
                return "星期一";
            case DayOfWeek.Tuesday:
                return "星期二";
            case DayOfWeek.Wednesday:
                return "星期三";
            case DayOfWeek.Thursday:
                return "星期四";
            case DayOfWeek.Friday:
                return "星期五";
            case DayOfWeek.Saturday:
                return "星期六";
            case DayOfWeek.Sunday:
                return "星期日";
        }
        return "未知";
    }


    public static int GetWeekIndex(this DateTime time)
    {
        switch (time.DayOfWeek) {
            case DayOfWeek.Monday:
                return 0;
            case DayOfWeek.Tuesday:
                return 1;
            case DayOfWeek.Wednesday:
                return 2;
            case DayOfWeek.Thursday:
                return 3;
            case DayOfWeek.Friday:
                return 4;
            case DayOfWeek.Saturday:
                return 5;
            case DayOfWeek.Sunday:
                return 6;
        }
        return -1;
    }

    public static bool IsToday(this DateTime day)
    {
        var now = DateTime.Now;
        if (day.Year == now.Year && (day.Month == now.Month) && (day.Day == now.Day)) {
            return true;
        }
        return false;
    }

    public static bool IsSameDay(this DateTime today, DateTime day)
    {
        if (day.Year == today.Year && (day.Month == today.Month) && (day.Day == today.Day)) {
            return true;
        }
        return false;
    }

    /// <summary>
    /// 获取当前时间的毫秒级时间戳（13位）
    /// </summary>
    public static long GetTimestamp13(this DateTime time)
    {
        var ts = time.ToUniversalTime() - new DateTime(1970, 1, 1);
        return (long)ts.TotalMilliseconds;
    }

    /// <summary>
    /// 获取当前时间的秒级时间戳（10位）
    /// </summary>
    public static long GetTimestamp10(this DateTime time)
    {
        var ts = time.ToUniversalTime() - new DateTime(1970, 1, 1);
        return (long)ts.TotalSeconds;
    }
}